import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/ui/device/device_repair_submit_page.dart';
import 'package:ls_work/util/ext_utils.dart';

import '../../viewmodel/device/device_repair_list_view_model.dart';

class DeviceRepairListFragment extends BaseStatefulMvvmWidget {
  final String buildingId;

  DeviceRepairListFragment(this.buildingId);

  @override
  State<StatefulWidget> createState() => _DeviceRepairListState();
}

class _DeviceRepairListState extends BaseMvvmListState<
    DeviceRepairListViewModel, DeviceRepairListFragment> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  Widget get separatorDivider => Container(
        height: 10,
      );

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 10);

  @override
  bool get canPullUp => true;

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Column(
          children: [
            CommonText(item.name, textSize: 17, textColor: Colours.app_main),
            Container(
              height: 10,
            ),
            CommonText(item.serialNumber, textSize: 17),
            Container(
              height: 10,
            ),
            CommonText(item.buildingName??"", textSize: 14, textColor: Color(0xff545454)),
          ],
        ).setWeight(2),
        Container(
          width: 0.5,
          height: 135,
          margin: EdgeInsets.symmetric(vertical: 10),
          color: Colors.grey,
        ),
        Stack(
          alignment: Alignment.centerLeft,
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                titleValueWidget("设备位置", item.location??"")
                    .addToContainer(margin: EdgeInsets.only(bottom: 7)),
                CommonText("最近一次维保时间：${item.maintenanceDate?.changeTime(format: [yyyy,'-',mm,'-',dd])}",
                        textSize: 14, height: 1.4)
                    .addToContainer(margin: EdgeInsets.only(bottom: 7)),
                titleValueWidget("下次维保时间", item.nextMaintenanceDate?.changeTime(format: [yyyy,'-',mm,'-',dd])??"")
                    .addToContainer(margin: EdgeInsets.only(bottom: 7)),
                titleValueWidget("维保人", item.maintenancePersonnel??"")
                    .addToContainer(margin: EdgeInsets.only(bottom: 7)),
                titleValueWidget("手机号", item.maintenancePersonnelPhone??""),
              ],
            ),
            CommonText(item.statusName, textColor: item.status==1?Colors.red:Colors.blue, textSize: 13)
                .addToContainer(
                    margin: EdgeInsets.only(right: 10),)
                .setLocation(right: 0,top: 0)
          ],
        )
            .addToContainer(
                padding: EdgeInsets.only( left: 15))
            .setWeight(5)
      ],
    ).onTap(() {
      Go().push(DeviceRepairSubmitPage(id: item.id.toString(),));
    }).addToContainer(
        margin: EdgeInsets.symmetric(
          horizontal: 16,
        ),
        decoration:
            BoxDecoration(color: Colors.white, borderRadius: 16.borderRadius));
  }


  @override
  DeviceRepairListViewModel createViewModel() {
    return DeviceRepairListViewModel(context,widget.buildingId);
  }

  Widget titleValueWidget(String title, String value) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        CommonText('$title：', textSize: 14),
        CommonText('$value', textSize: 14).setWeight(1)
      ],
    );
  }

}
